package com.nvwa.mvp.word.service;

import com.nvwa.mvp.word.dto.PhoneRecord;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.nvwa.word.WordHelper;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * ExportWordService 类。
 *
 * @author wangjing
 * @date 2024-12-05 [wangjing] 创建。
 */
@Service
public class ExportWordService {

    public ResponseEntity<byte[]> export() {
        String templateFileName = "phonemodel.doc";
        String newFileName = "new.docx";
        Map<String, String> placeholders = initNoParamPlaceholders();
        try {
            return WordHelper.export(placeholders, templateFileName, newFileName);
        } catch (IOException e) {
            System.out.println("执行WORD导出失败");
        }
        return null;
    }

    private Map<String, String> initNoParamPlaceholders() {
        Map<String, String> paramPlaceholders = new HashMap<>();
        paramPlaceholders.put("${applyCode}", "123456");
        paramPlaceholders.put("${phoneTime}", "2024-10-10");
        paramPlaceholders.put("${phoneUnit}", "广电总局");
        paramPlaceholders.put("${phoneDuty}", "局长");
        paramPlaceholders.put("${phoneNumber}", "13311113333");
        paramPlaceholders.put("${R1}", "√");
        paramPlaceholders.put("${R2}", "□");
        paramPlaceholders.put("${phoneContent}", "本次的电话内容是...");
        paramPlaceholders.put("${phoneRecorder}", "张山");
        paramPlaceholders.put("${phoneRemark}", "这里是备注...");
        return paramPlaceholders;
    }
}
